#lang racket
(define (out p)
  (display p (current-output-port)))

(define (error p)
  (display p (current-error-port)))

(define main
  (let ((image_width  256)
        (image_height 256))
    (out "P3\n")
    (out image_width)
    (out " ")
    (out image_height)
    (out "\n255\n")
    (define (iter j i)
      (cond ((>= j 0)
             (error "\rScanlines remaining:")
             (error j)
             (error " ")
             (if (< i image_width)
                 (let* ((r (/ i (- image_width 1)))
                        (g (/ j (- image_height 1)))
                        (b (/ 1 4))
                        (ir (floor (* 256 r)))
                        (ig (floor (* 256 g)))
                        (ib (floor (* 256 b))))
                   (out ir)
                   (out " ")
                   (out ig)
                   (out " ")
                   (out ib)
                   (out "\n")
                   (iter j (+ i 1)))
                 (iter (- j 1) 0)))))
    (iter (- image_height 1) 0)
    (error "\nDone.\n")))

main